package org.linlinjava.litemall.db.service;

import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
import com.github.pagehelper.PageHelper;
import me.chanjar.weixin.common.error.WxErrorException;
import org.apache.commons.lang3.StringUtils;
import org.linlinjava.litemall.db.dao.LitemallArrivalReminderMapper;
import org.linlinjava.litemall.db.domain.LitemallArrivalReminder;
import org.linlinjava.litemall.db.domain.LitemallArrivalReminderExample;
import org.linlinjava.litemall.db.domain.LitemallBookReview;
import org.linlinjava.litemall.db.domain.LitemallUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author piao
 * @Date 2021/03/19
 */
@Service
public class LitemallArrivalReminderService {
    @Autowired
    private LitemallArrivalReminderMapper arrivalReminderMapper;

    public List<LitemallArrivalReminder> listAll(String bookName, Integer page, Integer limit) {
        LitemallArrivalReminderExample example = new LitemallArrivalReminderExample();
        LitemallArrivalReminderExample.Criteria criteria = example.or();
        criteria.andDeletedEqualTo(false);
        if (StringUtils.isNotBlank(bookName)) {
            criteria.andBookNameLike(bookName + "%");
        }
        example.setOrderByClause("add_time desc");
        PageHelper.startPage(page, limit);
        return arrivalReminderMapper.selectByExample(example);
    }

    public List<LitemallArrivalReminder> queryByProductId(Integer productId) {
        LitemallArrivalReminderExample example = new LitemallArrivalReminderExample();
        example.or().andProductIdEqualTo(productId).andDeletedEqualTo(false);
        return arrivalReminderMapper.selectByExample(example);
    }

    public void update(LitemallArrivalReminder arrivalReminder) {
        arrivalReminder.setUpdateTime(LocalDateTime.now());
        arrivalReminderMapper.updateByPrimaryKeySelective(arrivalReminder);
    }


}
